<?php if (defined("YTDJ") or die());

class Request {
	
	static $get;
	static $post;
	static $session;
	static $cookie;
	
	static function get($var = '*', $from = "get", $default = null) {
		switch ($from) {
			case "get":
				if (!isset(self::$get)) {
					self::$get = $_GET;
				}
				if ($var == '*') {
					$ret = self::$get;
				} else {
					$ret = self::$get[$var];
				}
				break;	
			case "post":	
				if (!isset(self::$post)) {
					self::$post = $_POST;
				}
				if ($var == '*') {
					$ret = self::$post;
				} else {
					$ret = self::$post[$var];
				}
				break;
			case "session":
				if (!isset(self::$session)) {
					self::$session = $_SESSION;
				}
				if ($var == '*') {
					$ret = self::$session;
				} else {
					$ret = self::$session[$var];
				}
				break;
			case "cookie":
				if (!isset(self::$cookie)) {
					self::$cookie = $_COOKIE;
				}
				if ($var == '*') {
					$ret = self::$cookie;
				} else {
					$ret = self::$cookie[$var];
				}
				break;
		}
		if (isset($ret)) {
//			if (is_array($ret)) {
//				array_walk($ret, 'urld');
//			} else {
//				$ret = urldecode($ret);
//			}
			return $ret;
		} else {
			return $default;
		}
	}
	
	static function set($var, $value, $to = "get") {
		switch ($to) {
			case "get":
				if (!isset(self::$get)) {
					self::$get = $_GET;
				}
				self::$get[$var] = $value;
				break;	
			case "post":	
				if (!isset(self::$post)) {
					self::$post = $_POST;
				}
				self::$post[$var] = $value;
				break;
			case "session":
				if (!isset(self::$session)) {				
					self::$session = $_SESSION;
				}
				self::$session[$var] = $value;
				$_SESSION[$var] = $value;
				break;
			case "cookie":
				if (!isset(self::$cookie)) {				
					self::$cookie = $_COOKIE;
				}
				self::$cookie[$var] = $value;
				setcookie($var, $value, time()+60*60*24*90);
				break;
		}
	}
	
}
?>